﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Abp.Application.Services.Dto;
using AbpLearningDemo.Companies;
using AbpLearningDemo.Companies.Dto;
using AbpLearningDemo.Web.Models.Companies;
using Guid = System.Guid;

namespace AbpLearningDemo.Web.Controllers
{
    public class CompaniesController : AbpLearningDemoControllerBase
    {
        private readonly ICompanyAppService _companyAppService;

        public CompaniesController(ICompanyAppService companyAppService)
        {
            _companyAppService = companyAppService;
        }

        public async Task<ActionResult> Index()
        {
            IReadOnlyList<CompanyListDto> companies = (await _companyAppService.GetCompaniesAsync(new GetCompaniesInput() { MaxResultCount = int.MaxValue })).Items;
            CompanyListViewModel model = new CompanyListViewModel
            {
                Companies = companies,
            };

            return View(model);
        }

        public async Task<ActionResult> EditCompanyModal(Guid companyId)
        {
            CompanyListDto company = await _companyAppService.GetCompanyAsync(new NullableIdDto<Guid>(companyId));
            EditCompanyModalViewModel model = new EditCompanyModalViewModel
            {
                Company = company,
            };
            return View("_EditCompanyModal", model);
        }
    }
}